{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "42140047",
   "metadata": {},
   "source": [
    "-----------\n",
    "\n",
    "* 本学习记录人：  \n",
    "* 学习时间：  \n",
    "* week06  \n",
    "* [参考文档](https://www.python.org/doc/)\n",
    "* [许老师的博客](https://www.cnblogs.com/xuzhichao)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e88f56d4",
   "metadata": {},
   "source": [
    "# 本周学习时间\n",
    "\n",
    "\n",
    "## 1.认识[列表](https://docs.python.org/3/tutorial/introduction.html#lists)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 2.列表的取值\n",
    "## 3.列表的一般放法\n",
    "## 4.列表的高级方法\n",
    "### 1.1初始列表\n",
    "\n",
    "> 1.列表的样式：[元素1，元素2.....]\n",
    "> 2.列表的性质：\n",
    ">> 1. 列表式是有顺序的（Sequence,Tpyes序列类型的数据），第一个元素的位置/索引/(index)是0\n",
    ">> 2.列表可以存放不同的类型数据，**但是**\n",
    ">> 2.列表可以按照序列数据 进行 取值（index）或切片（slices）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "308ae27f",
   "metadata": {},
   "outputs": [],
   "source": [
    "username_database = \"Alex，Jack，Yrr，Marry\"\n",
    "username_database_list = [\"Alex\",\"Jack\",\"Yrr\",\"Marry\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "be314d32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack\n",
      "Jack\n"
     ]
    }
   ],
   "source": [
    "# 目标取出每一个账号名称\n",
    "print(username_database[5:9])  #字符串就显得比较麻烦\n",
    "print(username_database_list[1]) # 列表可以按照独立元素进行取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "d3d0c869",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_database_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "fa2fd353",
   "metadata": {},
   "outputs": [],
   "source": [
    "#列表中可以包含不同的 types （int\\float\\str..也可是列表）数据 * 不常这样用\n",
    "different_types_list =[\"Alex\",18,175.5,[\"广东省广州南方学院\",510970]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "fe513fcc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "e8719e7f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "510970"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[3][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "861aac33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考： 取值是否需要知道列表的长度？如果列表只有5个元素，\n",
    "# 取值不能取5以上\n",
    "squares = [1,4,9,16,25]\n",
    "print(squares[0])\n",
    "#print(squares[10]) #IndexError(索引错误): list index out of range\n",
    "#一般 列表的取值需要先知道/清楚列表的长度，取值不要超过其长度范围\n",
    "len(squares)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc0103b8",
   "metadata": {},
   "source": [
    "### 2.1 切片(slices)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "988acf56",
   "metadata": {},
   "outputs": [],
   "source": [
    "squares = [1,4,9,16,25]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "c7b174aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#（从左往右取） 9和16：\n",
    "squares[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "59367379",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 9]"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[-4:-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "326d4859",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从右往左取）9和16\n",
    "squares[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "9791ce16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16, 25]"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从左往右取） 9，16，25：结论：取到末尾或者首位都一律不写最好\n",
    "squares[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "428b3e3c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16, 25]"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从右往左取） 9，16，25：\n",
    "squares[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "704698fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9]"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "id": "013b2da6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 9]"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取1,9？,回顾切片的步长step  [start,stop,step]\n",
    "squares[:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3becb28f",
   "metadata": {},
   "source": [
    "## 2.2 列表取值实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "c166e4bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u'] # vowels 元音  [\"数字媒体\"]\n",
    "word = \"Milliways\"             # word ：目标文本    文本 1000000个字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "0911b76d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 请检查 word 中出现了哪些 vowels 中的元素，并打印出来\n",
    "# 知识点：\n",
    "# 1. for 循环和 if条件判断\n",
    "# 2. in 判断是否存在在列表中 \n",
    "for i in word:\n",
    "    if i in vowels:\n",
    "        print(i)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "59287ac6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M\n",
      "i\n",
      "l\n",
      "l\n",
      "i\n",
      "w\n",
      "a\n",
      "y\n",
      "s\n"
     ]
    }
   ],
   "source": [
    "for i in word:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "ae22262c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "e\n",
      "i\n",
      "o\n",
      "u\n"
     ]
    }
   ],
   "source": [
    "for i in vowels:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "32145923",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "i\n"
     ]
    }
   ],
   "source": [
    "# 请检查 vowels 中出现的 word ?\n",
    "for i in vowels:\n",
    "#     print(i)\n",
    "    if i in word:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "e19bc209",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-162-e613bc5654a0>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 扩展案例： 枚举：确定其出现的 位置\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0muser_word\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入你要查询的文本：\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mv\u001b[0m \u001b[1;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0muser_word\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mv\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mvowels\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m         \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m    858\u001b[0m                 \u001b[1;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    859\u001b[0m             )\n\u001b[1;32m--> 860\u001b[1;33m         return self._input_request(str(prompt),\n\u001b[0m\u001b[0;32m    861\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    862\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_header\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m    902\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    903\u001b[0m                 \u001b[1;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 904\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Interrupted by user\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    905\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    906\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid Message:\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "# 扩展案例： 枚举：确定其出现的 位置\n",
    "user_word = input(\"请输入你要查询的文本：\")\n",
    "for i,v in enumerate(user_word):\n",
    "    if v in vowels:\n",
    "        print(i,v)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee4bb2b8",
   "metadata": {},
   "source": [
    "# 3列表的一般方法\n",
    "\n",
    "\n",
    "| 列表的方法 | Description| 一般用在什么情景下 |\n",
    "| ---------------- | ------------ | ------------- |  \n",
    "|append | 列表的新增：增加元素至列表的末尾 | 新建列表 |  \n",
    "| clear | 列表的清除 | 清空列表元素 |\n",
    "| pop |列表删除：默认删除列表最后一个 | 删除列表最后一个 |\n",
    "| copy |列表复制 | 需要一个同样的新列表|\n",
    "| count |列表元素的次数 | 需要某元素在列表中出现次数 |\n",
    "| extend |列表大量增加 | 用于一个列表整体添加到另外一个列表的末尾|\n",
    "| index |确定元素索引值 | 寻找列表中当前元素第一次出现的索引位置 |\n",
    "|insert | 元素的插入 | 可将元素的插入确定的索引值位置|\n",
    "|reverse |列表元素倒置 |需将元素倒置可用|\n",
    "|sort |整理列表|列表中的元素已经按字母顺序排列且不可重置|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "id": "0b317e79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 210,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdfa062b",
   "metadata": {},
   "source": [
    "> 1.append() 列表的新增，增加元素至列表的末尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "id": "a1e6d6e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "id": "b7ff0354",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Alex\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "f278335d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'Alex']"
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe4fe910",
   "metadata": {},
   "source": [
    "> 2.remove() 选择列表的内容/值（values），删除\n",
    ">> * 注意：remove（）的一般步骤：1.先查询in 2.再删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "id": "1f933a84",
   "metadata": {},
   "outputs": [],
   "source": [
    "num_list = [1,4,4,6,5,4,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "id": "064265a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "num_list.remove(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "id": "f980100c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 6, 5, 4, 2]"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "num_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "id": "937ee9d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove()的一般步骤 \n",
    "if \"Mary\" in names:  # 先查询，再删除  \n",
    "    names.remove(\"Mary\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "d13bd20c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jan', 'Jack', 'Alex']"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "id": "560bbf09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "id": "d3f15e9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.remove(\"Mike\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "id": "853797d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jan', 'Jack', 'Alex']"
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93667ea0",
   "metadata": {},
   "source": [
    "> 3.pop() pop(index=-1, /) 默认的删除 最后一位的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "4172f393",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "id": "6a9ada67",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop() # 默认删除最后一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "id": "f281abd8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jan', 'Jack']"
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "id": "ceacca96",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除实践：\n",
    "stu_id_分数 = [78,88,77,78,90,90,78,88,90,89,95]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "id": "ac1c24f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove 时 ，可能需要重复运行 才可以按照指定的要求删除所有的值， \n",
    "# 分数在 低于85分 的删除\n",
    "stu_id_分数 = [78,88,77,78,90,90,78,88,90,89,95]\n",
    "for j in stu_id_分数:\n",
    "    if j<85: #判断是否还有值小于85 \n",
    "        for i in stu_id_分数:\n",
    "            if i < 85:\n",
    "                stu_id_分数.remove(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "id": "1a7f246d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[88, 90, 90, 88, 90, 89, 95]"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id_分数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "id": "6be3ef4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除实践: 需要执行两次 即可删干净\n",
    "stu_id_分数 = [78,88,77,78,90,90,78,88,90,89,95,77,78,98,77,82]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "id": "8ffae724",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前的列表： [78, 88, 77, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 0 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 77, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 1 77\n",
      "当值小于85时 要删除的值： 77\n",
      "当前的列表： [88, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 2 90\n",
      "当前的列表： [88, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 3 90\n",
      "当前的列表： [88, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 4 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 5 90\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 6 89\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 7 95\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 8 77\n",
      "当值小于85时 要删除的值： 77\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 77, 82]\n",
      "循环遍历结果： 9 98\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 77, 82]\n",
      "循环遍历结果： 10 77\n",
      "当值小于85时 要删除的值： 77\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 0 88\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 1 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 2 90\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 3 88\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 4 90\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 5 89\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 6 95\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 7 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 98, 82]\n",
      "循环遍历结果： 8 82\n",
      "当值小于85时 要删除的值： 82\n"
     ]
    }
   ],
   "source": [
    "for j in stu_id_分数:\n",
    "    if j<85:\n",
    "        for i,v in enumerate(stu_id_分数):\n",
    "            print(\"当前的列表：\",stu_id_分数)\n",
    "            print(\"循环遍历结果：\",i,v)\n",
    "            if v < 85:\n",
    "                print(\"当值小于85时 要删除的值：\",stu_id_分数.pop(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "id": "96e93421",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[88, 90, 90, 88, 90, 89, 95, 98]"
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id_分数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "id": "c97ce0d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function copy:\n",
      "\n",
      "copy() method of builtins.list instance\n",
      "    Return a shallow copy of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.copy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "id": "3a3dbdb6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Jan', 'Jack'] ['Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "names2=names.copy()\n",
    "print(names,names2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "id": "2e6b2846",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.count(\"Jack\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "id": "b9ee1cca",
   "metadata": {},
   "outputs": [],
   "source": [
    "names3 =[\"Honey\",\"Hello\"]\n",
    "names.extend(names3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 244,
   "id": "2bbc9fc6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 245,
   "id": "e1407ffd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jan', 'Jack', 'H', 'Honey', 'Hello']"
      ]
     },
     "execution_count": 245,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "id": "f83626a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function index:\n",
      "\n",
      "index(value, start=0, stop=9223372036854775807, /) method of builtins.list instance\n",
      "    Return first index of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "id": "2a537c1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 251,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.index(\"Jan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "id": "949f7084",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(1,\"You\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 254,
   "id": "b38e074b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 255,
   "id": "78f1c4f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jan', 'You', 'Jack', 'H', 'Honey', 'Hello']"
      ]
     },
     "execution_count": 255,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "id": "236d0d96",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function reverse:\n",
      "\n",
      "reverse() method of builtins.list instance\n",
      "    Reverse *IN PLACE*.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.reverse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "id": "d8ff75d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.reverse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 258,
   "id": "c95c904d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Hello', 'Honey', 'H', 'Jack', 'You', 'Jan']"
      ]
     },
     "execution_count": 258,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 260,
   "id": "7b2a2028",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 263,
   "id": "1869e47d",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.sort(reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "d7e36b46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['You', 'Jan', 'Jack', 'Honey', 'Hello', 'H']"
      ]
     },
     "execution_count": 264,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b05534f7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
